<template>
  <div class="mod-menu">
    <!-- <div>以下项1天内修改仅可生效1次（当日24点前多次修改，以最后一次修改为准，次日凌晨5点后生效）</div> -->
    <el-table :data="dataList" row-key="Id" border style="width: 100%;margin-top: 10px; ">
      <el-table-column prop="level" align="center" label="会员等级">
      </el-table-column>
      <el-table-column prop="role_name" align="center" label="等级名称">
      </el-table-column>
      <el-table-column prop="outer_role_name" align="center" label="输出名称">
      </el-table-column>
      <el-table-column prop="threshold" align="center" label="升级消费金额">
      </el-table-column>
      <el-table-column prop="upgrade_num" align="center" v-if="roleType==2" label="升级推荐人数">
      </el-table-column>
      <el-table-column prop="discount" align="center" label="会员折扣">
        <template slot-scope="scope">
          <span>{{scope.row.discount}}折</span>
        </template>
      </el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id,scope.row.level)">修改</el-button>
          <!--  <el-button  type="text" size="small" @click="deleteHandle(scope.row.id)">完成</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <!-- <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pamars.page"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pamars.limit"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination> -->
    <!-- 弹窗, 新增 / 修改 -->
    <group-booking-add-update v-if="addOrUpdateVisible" ref="groupBookingAddUpdate" @updataList='updataList'></group-booking-add-update>
  </div>
</template>

<script>
import groupBookingAddUpdate from './add-update-member-rights.vue'
import seviceApi from '@/api/serviceApi.js'
export default {
  data () {
    return {
      dataForm: {},
      // pamars:{
      //   page:1,
      //   limit:10,
      // },
      totalPage: 0,
      dataList: [],
      dataListLoading: false,
      addOrUpdateVisible: false
    }
  },
  components: {
    groupBookingAddUpdate
  },
  computed: {
    roleType: {
      get () { return this.$store.state.user.roleType }
    }
  },
  mounted () {
    this.getList()
  },
  methods: {
    updataList (e) {
      if (e == 1) {
        this.getList()
      }
    },
    // 活动状态
    activeState (row, column) {
      let status = row.active_state
      if (status === 0) {
        return '未开始'
      } else if (status === 1) {
        return '进行中'
      } else {
        return '已结束'
      }
    },
    // 获取列表
    getList () {
      seviceApi.getShopUserRoleConfigList().then(res => {
        if (res && res.data.code == 200) {
          this.dataList = res.data.list
          this.totalPage = res.data.totalCount
        }
      })
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pamars.limit = val
      this.getList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.pamars.page = val
      this.getList()
    },
    // 查询
    getDataList () {
      this.getList()
    },
    // 新增 / 修改
    addOrUpdateHandle (id, level) {
      if (level == 4 && this.roleType != 2) {
        this.$message('仅平台商家可操作')
        return false
      }
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.groupBookingAddUpdate.init(id, level)
      })
    },
    // 拼团管理商品页
    goProduct (id) {
      this.$router.push({ name: 'gb-product', query: { id: id } })
    },
    // 删除
    deleteHandle (id) {
      this.$confirm(`确定要删除该条数据?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        seviceApi.delGroupbuyActivity(id).then(res => {
          if (res && res.data.code == 200) {
            this.$message({
              message: '删除成功',
              type: 'success'
            })
            this.getList()
          }
        })
      }).catch(() => { })
    }
  }
}
</script>
